import 'package:flutter/material.dart';
import 'package:flutter_swiper_null_safety/flutter_swiper_null_safety.dart';
import 'package:mall/constant/app_colors.dart';
import 'package:mall/constant/app_dimens.dart';

import 'package:mall/gen/r.dart';
import 'package:mall/modules/model/home_entity.dart';
import 'package:mall/ui/widgets/cached_image.dart';
import 'package:mall/router/navigator_util.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

class TabHomeBanner extends StatelessWidget {
  final List<HomeModelBanner> _bannerData;

  TabHomeBanner(this._bannerData);

  @override
  Widget build(BuildContext context) {
    return ClipRRect(
      borderRadius: BorderRadius.circular(8),
      child: Container(
        color: AppColors.C_F0F0F0,
        alignment: Alignment.center,
        height: 150,
        // width: double.infinity,
        child: _bannerData.length == 0
            ? Image.asset(R.image.placeholderImage.path)
            : Swiper(
                onTap: (index) {
                  NavigatorUtil.goWebView(context, _bannerData[index].name, _bannerData[index].link);
                },
                itemCount: _bannerData.length,
                scrollDirection: Axis.horizontal,
                //滚动方向，设置为Axis.vertical如果需要垂直滚动
                loop: true,
                //无限轮播模式开关
                index: 0,
                //初始的时候下标位置
                autoplay: false,
                itemBuilder: (BuildContext buildContext, int index) {
                  print(_bannerData[index].url);
                  return CachedImageView(double.infinity, double.infinity, _bannerData[index].url ?? "");
                },
                duration: 5000,
                pagination: SwiperPagination(
                    alignment: Alignment.bottomCenter,
                    builder: DotSwiperPaginationBuilder(
                      size: ScreenUtil().setWidth(AppDimens.DIMENS_18),
                      activeSize: ScreenUtil().setWidth(AppDimens.DIMENS_18),
                      color: Colors.white,
                      activeColor: AppColors.C_FF5722,
                    )),
              ),
      ),
    );
  }
}
